/* ========================================================================== */
/*   Beeper.h                                                                 */
/*   (c) 2012 Team 7 Hogeschool Utrecht ICT TI                                */
/*		Lars Stolwijk, Gerben Boot, Guido van Hienen, Marcel Boelen			  */
/*                                                                            */
/*   Generates instructed sounds by switching the beeper on and off           */
/* ========================================================================== */

#ifndef __Beeper
#define __Beeper

#include "pRTOS.h"
#include "SoundEvent.h"
#include "armboard.h"

class Beeper : public RTOS::task {
	public:	
		Beeper(int prio) : RTOS::task(prio, "BeepTask"), BTTimer( this, "BTTimer" ), BTClock( this, 500 US, "BTClock"), SoundChannel( this, "SoundChannel" ){}
		void PlaySound(int freq, int time);
		
	private:
		enum State { WAITING, PLAYINGSOUND };
		State CurrentState;

		RTOS::timer BTTimer;
		RTOS::clock BTClock;
		RTOS::channel< SoundEvent, 50 > SoundChannel;

		void main();
		void SwitchBeepBit();
		bool speakerOn;
};

#endif